import ast
import unittest
from tools.lbs_utils import *
"""
lbs_utils 单元测试
"""


class UtilsTestCase(unittest.TestCase):

    def test_get_start_index(self):
        part_genes = [-1, -1, 0, 0, 1, 1]
        start_index = get_start_index(part_genes)
        self.assertEqual(start_index, 4)

    def test_get_order_interval(self):
        plans = [-1, -1, 0, 0, 0, 0, 2, 0]
        order1 = None
        order2 = 2
        start_index, end_index = get_order_interval(plans, order1, order2)
        self.assertEqual(start_index, 0)
        self.assertEqual(end_index, 6)

    def test_get_lock_travel_num(self):
        inventory = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1]
        genes = [0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 2, 0, 0, 3, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1]
        travels = get_lock_travel_num(inventory, genes)
        self.assertEqual(travels, {2: 1, 3: 2, 1: 2})

    def test_get_lock_delay_num(self):
        inventory = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1]
        genes = [0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 2, 0, 0, 3, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1]
        delays = get_lock_delay_num(inventory, genes)
        self.assertEqual(delays, {2: 2, 3: 1, 1: 2})


if __name__ == '__main__':
    unittest.main()
